package com.gitee.wsl.math.matrix


class IdentityMatrix(n: Int) : SquareMatrix(n) {
    /**
     * Constructor.
     *
     * @param n
     * the number of rows == the number of columns
     */
    init {
        for (i in 0 until n) m_aValues[i][i] = 1f
    }

    companion object {
        /**
         * Convert a square matrix into an identity matrix.
         *
         * @param sm
         * the square matrix to convert
         */
        fun convert(sm: SquareMatrix) {
            for (r in 0 until sm.m_nRows) {
                for (c in 0 until sm.m_nCols) {
                    sm.m_aValues[r][c] = (if (r == c) 1 else 0).toFloat()
                }
            }
        }
    }
}